#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
 
/**
    From https://ideone.com/tCIzl
    */

const int mi = 19931117;
int lsh[500020], lsht[500020], lshmr;
void initialize (void)
{
    sort(lsh, lsh + lshmr);
    int cnt = 0;
    for (int i = 0; i < lshmr; i++)
    {
        if (i == 0 || lsh[i] != lsh[i - 1])
            lsht[cnt++] = lsh[i];
    } lshmr = cnt;
}
inline int place (int a)
{
    int st = 0, ed = lshmr, mid;
    while (ed - st > 1)
    {
        mid = (st + ed) >> 1;
        if (lsht[mid] > a) ed = mid;
        else st = mid;
    } return st + 1;
}
pair<int, int> require[250010];
pair<int, int> rs[250010], trs[250010]; int trmr;
bool comp (const pair<int, int>& a, const pair<int, int>& b)
{
    if (a.first != b.first) return a.first < b.first;
    else return a.second > b.second;
}
 
int jump[20][500010], maxj;
void jump_st (void)
{
    int p = 0; jump[0][lshmr + 1] = mi;
    for (int i = lshmr; i >= 1; i--)
    {
        if (p < trmr && i == trs[p].first) jump[0][i] = trs[p++].second + 1;
        else jump[0][i] = jump[0][i + 1];
    }
    bool valid;
    for (int i = 1; ; i++)
    {
        valid = false;
        jump[i][lshmr + 1] = mi;
        for (int k = 1; k <= lshmr; k++)
        {
            if (jump[i - 1][k] == mi) jump[i][k] = mi;
            else jump[i][k] = jump[i - 1][jump[i - 1][k]];
            if (jump[i][k] < mi) valid = true;
        }
        if (valid == false) { maxj = i - 1; break; }
    }
}
int max_time (int s, int e)
{
    if (s >= e) return 0;
    int ts = s, ans = 0; ++e;
    for (int j = maxj; j >= 0 && ts < e; j--)
        if (jump[j][ts] <= e) ts = jump[j][ts], ans += (1 << j);
    return ans;
}
set<pair<int, int> > query;
typedef set<pair<int, int> >::iterator ptr; int ans;
bool judge (int i)
{
    int l = require[i].first, r = require[i].second;
    ptr t1, t2;
    t1 = query.lower_bound(make_pair(l, mi));
    if (t1 == query.begin()) return false; else --t1;
    if (t1->second < l) return false;
    t2 = --query.lower_bound(make_pair(r, mi));
    if (t1 != t2) return false;
    if (t1->second < r) return false;
    int ll = t1->first, rr = t1->second;
    int tans = max_time(ll, l - 1) + max_time(r + 1, rr) + 1;
    int sans = max_time(ll, rr);
    if (tans < sans) return false;
    else
    {
        query.erase(t1);
        if (ll <= l - 1) query.insert(make_pair(ll, l - 1));
        if (r + 1 <= rr) query.insert(make_pair(r + 1, rr));
        return true;
    }
}
int main ()
{
    int n, ans; scanf("%d", &n), lshmr = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d", &require[i].first, &require[i].second);
        lsh[lshmr++] = require[i].first;
        lsh[lshmr++] = require[i].second;
    }
    initialize();
    for (int i = 0; i < n; i++)
    {
        int l = place(require[i].first), r = place(require[i].second);
        require[i].first = l, require[i].second = r;
        rs[i] = make_pair(l, r);
    }
    sort(rs, rs + n, comp), trmr = 0; int p;
    for (int i = n - 1; i >= 0; i--)
    {
        if (i == n - 1 || rs[i].second < rs[p].second)
            trs[trmr++] = rs[i], p = i;
    }
    jump_st();
    query.insert(make_pair(1, lshmr));
    printf("%d\n", ans = max_time(1, lshmr));
    for (int i = 0; i < n; i++)
        if (judge(i)) printf("%d ", i + 1);
    printf("\n");
    return 0;
}
